// pages/order/index.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    loading: 0,
    page: 1,
    status: 0,
    lastpage: 0,
    listData: []

  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({ extConfig: app.getExtConfigSync() })
    if (options.status) {
      this.data.status = options.status;
      this.setData({ status: options.status });
    }
    this.loadOderList();
  },
  
  loadOderList: function (reload) {
    var that = this;

    if (reload == 1) {
      this.setData({
        loading: 0,
        page: 1,
        lastpage: 0,
        listData: [],
      });
    }

    var page = this.data.page;
    if (this.data.loading == 1 || this.data.lastpage == 1) {
      //console.log(this.data);
      return;
    }
    this.data.loading = 1;
    app.api("mall/dining_table_book/get", {
      page: page,
      limit: 10,
      order: 'id desc'
    }, function (res) {
      that.data.loading = 0;
      if (res.code != 200) {
        app.alert(res.msg);
        return;
      }
      if (res.data.list.length == 0) {
        that.data.lastpage = 1;
      }
      that.data.page++;
      that.setData({
        listData: that.data.listData.concat(res.data.list),
      });
    })

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
   

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    this.loadOderList(1);
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    this.loadOderList();
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})